#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import multiprocessing as mp


def pf(d, v1, lock):
    print('subprocess:%s' % os.getpid())
    for i in range(100):
        with lock:
            d['test'] += 1
            print(d)
            v1 += 1


def pt():
    spn = 5
    mgr = mp.Manager()
    d = {'test': 0}
    md = mgr.dict(d)
    v1 = 0
    lock = mp.Lock()
    ps = [mp.Process(target=pf, args=(md, v1, lock)) for i in
          range(spn)]
    for p in ps:
        p.start()
    for p in ps:
        p.join()
    print('done')
    print(md)
    print(d)
    print(v1)


if __name__ == '__main__':
    pt()
